<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../org/angular.min.js"></script>
    <script src="../../org/jquery.min.js"></script>
</head>

<body ng-app="app" ng-controller="ctrl">
    <button ng-click="testFather()">父级</button>
    <zyx-cms title="老周" color="#fff" background="green"></zyx-cms>
    <hr>
    <script>
        var m = angular.module('app', []);
        m.directive('zyxCms', [function() {
            return {
                restrict: 'E',
                template: '',
                scope: {
                    title: '@'
                },
                controller: ['$scope', function($scope) {
                    $scope.age = 18;
                }],
                //第一个参数scope，可以取到scope属性中的值，也可以取到controller中定义到scope下面的值，相当于是该指令的作用域。
                link: function(scope, elem, attr) {
                    $(elem).css({
                        'backgroundColor': attr['background'],
                        'color': attr['color']

                    }).html(scope.title + '年龄:' + scope.age);
                }
            }
        }])
        m.controller('ctrl', ['$scope', function($scope) {

        }])
    </script>
</body>

</html>
